import Vue from 'vue'
import Router from 'vue-router'
import Home from '../components/Home'
import Login from '../components/Login'
import Register from '../components/Register'
import Details from '../views/details'
import Order from '../views/Order'
import Cars from '../views/Cars'
import Sidentify from "../components/Sidentify"
import Search from "../components/Search"
import NotFound from "../views/NotFound";
import Personal from "../views/personal/Personal";
import MyTest from "../views/MyTest";
import ScrollTop from "../components/ScrollTop";
import Carousel from "../components/Carousel";

Vue.use(Router)

/*解决未捕获相同路由异常问题*/
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: '根',
      redirect: '/login'
    }, {
      path: '/login',
      name: '登录',
      component: Login
    }, {
      path: '/home',
      name: '主界面',
      component: Home,
      redirect: 'home/myCat',
      children: [{
        path: 'myCat',
        name: '全部猫咪',
        components: {
          cat: () => import('@/views/MyCat')
        }
      }, {
        path: 'cat1',
        name: '布偶猫',
        components: {
          cat: () => import('@/views/Cat1')
        }
      }, {
        path: 'cat2',
        name: '加菲猫',
        components: {
          cat: () => import('@/views/Cat2')
        }
      }, {
        path: 'cat3',
        name: '金渐层',
        components: {
          cat: () => import('@/views/Cat3')
        }
      }]
    }, {
      path: '/register',
      name: '注册界面',
      component: Register
    }, {
      path: '/details',
      name: '详情',
      component: Details
    }, {
      path: '/cars',
      name: '购物车',
      component: Cars
    }, {
      path: '/order',
      name: '支付',
      component: Order
    }, {
      path: '/sidentify',
      name: '验证码',
      component: Sidentify
    }, {
      path: '/search',
      name: '搜索',
      component: Search
    }, {
      path: '*',
      component: NotFound
    }, {
      path: '/personal',
      name: '我的个人中心',
      component: Personal,
      redirect: 'personal/info',
      children: [{
        path: 'info',
        name: '个人信息',
        components: {center: () => import('@/views/personal/Info')}
      },
        {
          path: 'changePwd',
          name: '修改密码',
          components: {center: () => import('@/views/personal/ChangePwd')}
        },
        {
          path: 'privacy',
          name: '隐私保护',
          components: {center: () => import('@/views/personal/Privacy')}
        }
      ]
    }, {
      path: '/t',
      name: '测试',
      component: MyTest
    },{
      path: '/scrollTop',
      name: '返回顶部',
      component: ScrollTop
    },{
      path: '/carousel',
      name: '走马灯',
      component: Carousel
    }
  ]
})
